#ifndef MyForm_H
#define MyForm_H

#include <QList>
#include "freedesktopmime.h"
#include "aboutplugins.h"
#include "MyFormBase.h"
#include <QErrorMessage>
class pluginsList;
class queueArea;
class QDragEnterEvent;


class MyForm : public MyFormBase
{
	Q_OBJECT
public:
	MyForm(QWidget *parent = 0);
	~MyForm();
public slots:
	void setPreview(QString filename);
	void setPreview(QIODevice *file, QString name);

private:
	class ErrorMessage;
	ErrorMessage* errorMessage;

	QFreeDesktopMime* freedesktopMime;
	pluginsList *allPlugins;
	int currentUploading; // Image uploding now

	void loadPlugins();
	signalSlotStratum *Stratum;
	addImagePluginStratum *addImageStratum;

	QList<UploadResult> LastUploadResult;
	queueArea *queue;

// table on a 'Help' tab about plugins
	AboutPlugins *pluginsTable;
	void dragEnterEvent(QDragEnterEvent *event) const;
	void dropEvent(QDropEvent *event);


private slots:
	void upload();
	inline void addPluginRow(const QStringList &descr) { pluginsTable->addRow(descr); }
	void addImagePluginWidget(QWidget* widget);

//	void reSelectPlugin(bool checked, uploadPluginClass *plugin);
	void setResultLabelText() const;
	void enableUploadButton(const bool enable = true);
	void disableUploadButton(const bool disable = true);
// This is upload progress
	void onTotalError(const QString &errorMessage);
	void onFileUploadFailed(const int index, const QString &errorMessage);
	void onUploadComplete(const QList<UploadResult> &uploadResult);
	void startNextFile(const int index); // receive info from plugin
	void fileUploaded(const int index, const UploadResult &result);
	void onCancel();
	void updateCurrentProgress(const int value, const int max); // receive info from plugin.
	void updateCurrentProgress(const int value, const int max, const int index); // receive info from plugin.




};

class MyForm::ErrorMessage : public QObject {
	public:
		void showMessage(const QString &message) {
			qWarning() << message;
			em->showMessage(message);
		}
		ErrorMessage(QWidget *parent = 0)
				: QObject(parent),
				em(new QErrorMessage(parent))
		{ }
	private:
		QErrorMessage *em;
	};


#endif
